<?php

namespace app\cps\controller;

use think\facade\Request;
use app\common\Common;
use app\cps\service\UserService;

class User extends Base
{
    private $service;

    public function __construct(UserService $service)
    {
        parent::__construct();
        $this->service = $service;
    }

    // 渲染用户列表页
    public function index()
    {
        return view();
    }

    // 渲染用户详情页
    public function info()
    {
        return view();
    }

    // 用户列表
    public function list()
    {
        $params = Request::param();

        $data = $this->service->getUserList($params, $this->getUserInfo());

        return Common::success($data);
    }

    // 查看用户详情
    public function detail()
    {
        $params = Request::param();

        $data = $this->service->getUserDetail($params, $this->getUserInfo());

        return Common::success($data);
    }

    // 获取用户充值/消费/观看数据
    public function getData()
    {
        $params = Request::param();

        $data = $this->service->getUserData($params);

        return Common::success($data);
    }

    // 渲染用户统计页
    public function statisticsIndex()
    {
        return view();
    }

    // 用户统计
    public function statistics()
    {
        $data = $this->service->getUserStatisticsData($this->getUserInfo());

        return Common::success($data);
    }

    // 定时器访问获取今日新增数据
    public function userToDayStatistics()
    {
        $data = $this->service->getUserToDayStatisticsData($this->getUserInfo());

        return Common::success($data);
    }

    // 近10天用户数据统计
    public function lastStatistics()
    {
        $data = $this->service->getLastUserStatisticsData($this->getUserInfo());

        return Common::success($data);
    }

    // 新增用户充值分析列表
    public function newUserRechargeAnalysis()
    {
        $data = $this->service->newUserRechargeAnalysisList($this->getUserInfo());
        return Common::success($data);
    }

    // 渲染用户分析数据页面
    // public function analysis()
    // {
    //     return view();
    // }

    // // 用户分析数据
    // public function userAnalysis()
    // {
    //     $params = Request::param();
    //     $data = $this->service->getUserAnalysisData($params);

    //     return Common::success($data);
    // }

    // 修改密码
    public function chargePass()
    {
        $params = Request::param();
        $data = $this->service->chargePassWord($params, $this->getUserInfo());

        if (!empty($data['message'])) {
            return Common::fail($data['message']);
        }
        return Common::success();
    }

    // 分销商用户列表
    public function distributionUserList()
    {
        $params = Request::param();

        try {
            validate(\app\cps\validate\Order::class)->scene('distribution_user_list')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getDistributionUserList($params);
        if (!empty($data['message'])) {
            return Common::fail($data['message']);
        }

        return Common::success($data);
    }
}